home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TPUG - Toronto PET Users Group
/
TPUG Users Group CD
/
TPUG Users Group CD.iso
/
PET
/
S-Super PET
/
(s)tz.d64
/
STORAGE.ASM
< prev
next >
Wrap
Assembly Source File
|
2009-01-18
|
5KB
|
164 lines
opt nolist ;program STORAGE shows how numbers are stored
xref cnvs2f_, printf_, itohs_,fstore_,suffixst_
xref printf_,getrec_,putchar_,putnl_,copystr_,length_
conversion ldd #title
jsr printf_
one ldd #prompt
jsr answer_same_line
ldd #buffer
jsr cnvs2f_ ;string in BUFFER converted to FP
ldd #memory_location ;stored to memory
jsr fstore_
ldd #FAC_string
jsr printf_
ldb #6 ;FAC1 uses 6 bytes
stb counter
ldd #$80 ;FAC1's address
jsr print_it ;FAC1 displayed
ldd #memory_string
jsr printf_ ;memory displayed
ldb #5 ;memory FP uses 5 bytes
stb counter
ldd #memory_location
jsr print_it
jsr putnl_
ldb #'2 ;maximum answer allowed
ldx #another_one
jsr get_a_char
cmpb #'1
if eq ;another one
ldb #1
jsr move_up
bra one
endif
jsr $d9a9 ;clear screen
clr $32 ;return to main menu
rts
print_it pshs d ;address where to read
clr buffer
loop
clra
ldb [,s] ;convert number to hex
pshs d
ldd #temp_storage ;destinatin of converted string
jsr itohs_
leas 2,s
ldd #buffer
pshs d
ldd #temp_storage
addd #2 ;to skip leading zeroes
jsr suffixst_
ldd #space ;destination address left on stack
jsr suffixst_
leas 2,s
ldd ,s ;increment address at ,s
addd #1
std ,s
dec counter
until eq
leas 2,s ;address removed from stack
ldd #buffer
jsr printf_
jsr putnl_
rts
;routine GET_A_CHAR inputs a char, returns it in B and ANSWER
;condensed from original described in tutorials
get_a_char stb answer ;B=maximum answer allowed
tfr x,d ;address of prompt in X
jsr printf_
two ldy #$130 ;emptying of keyboard memory
loop ;from $130 to $157
clr ,y+
cmpy #$158
until eq
loop
jsr $dd82 ;= BASIC's GET
cmpb #0 ;no answer ?
until ne
cmpb #'1
blo two ;no answer under '1
cmpb answer ;greatest answer allowed
bhi two
stb answer
jsr $d714 ;displays answer char
jsr putnl_
ldb answer
rts
;routine ANSWER_SAME_LINE inputs answer on same line as prompt
;no substitution (%s, %n) or tab chars allowed in prompt
;condensed from original described in tutorials
answer_same_line pshs d ;address of prompt
jsr length_ ;finds length of prompt
std nb_chars
puls d ;recalls address of prompt
jsr printf_
ldd #80 ;all purpose buffer
pshs d
ldd #buffer
jsr getrec_
leas 2,s ;number of chars read left in D
addd #buffer
tfr d,y
clr ,y ;null byte at end of string
ldd #buffer ;answer moved to start of BUFFER
pshs d ;address of BUFFER remains in D
addd nb_chars ;skip prompt
jsr copystr_
leas 2,s
rts
;routine MOVE_UP moves cursor up and erases lines where it passes
move_up stb nb_times
ldd #$06
jsr putchar_
loop
ldd #each_line
jsr printf_
dec nb_times
until eq
rts
nb_times rmb 1
each_line fcb $0b,$06,$00
counter rmb 1
memory_location rmb 5
title fcb 12,9 ;clear screen, move 1 tab
fcc "This program will display how numbers you input are stored"
fcb 13,13,9
fcc " PROGRAM CREATED BY ALAIN PROULX FOR ISPUG"
fcb 13,10,0 ;return, move down 1 line
prompt fcc "Input any number: "
fcb 0
FAC_string fcc "Here is how it is stored in FAC1: "
fcb 0
memory_string fcc "Here is how it is stored in memory: "
fcb 0
another_one fcc "[1] another one? [2] quit? "
fcb 0
space fcb 32,0
answer rmb 1
nb_chars rmb 1
temp_storage rmb 10
buffer rmb 80
end